﻿using System;
using System.Data.SqlClient;

namespace SoftwareEngineering_Project
{
    public class Room
    {
        string roomName;
         Boolean audio;
         Boolean video;
        SqlDataReader myReader = null;
        public Room(string name, Boolean audio, Boolean video)
        {
            roomName = name;
            this.audio = audio;
            this.video = video;
        }
        public Room()
        {
        }
        public Boolean AddtoDataBase()
        {
            string sqlcommand;
            sqlcommand = "INSERT INTO Room VALUES('" + roomName + "','" + audio + "','" + video + "');";
            DBConnection DB = new DBConnection();
            //DB.cnTransact.Open();
            // Myusers.DataSource = DB.ExecuteCommandquery(sqlcommand);
            if (DB.ExecuteCommandNonquery(sqlcommand))
            {
                (new Logs()).CreateLog("10", "");
                return true;
            }
            else
            {
                return false;
            }

            //DB.cnTransact.Close();

            return false;
        }
        public SqlDataReader getRooms(string sqlcommand)
        {
            DBConnection DB = new DBConnection();
            //DB.cnTransact.Open();
            myReader = DB.ExecuteCommandquery(sqlcommand);
            return myReader;
        }
        public Boolean  hasVideo(string sqlCommand)
        {
            Boolean hasvideo=false;
            DBConnection DB = new DBConnection();
            //DB.cnTransact.Open();
            myReader = DB.ExecuteCommandquery(sqlCommand);
            while (myReader.Read())
            {
               hasvideo = (Boolean)myReader[3];
            }
            return hasvideo;
        }

        public Boolean hasAudio(string sqlCommand)
        {
            Boolean hasaudio= false;
            DBConnection DB = new DBConnection();
            //DB.cnTransact.Open();
            myReader = DB.ExecuteCommandquery(sqlCommand);
            while (myReader.Read())
            {
                hasaudio = (Boolean)myReader[2];
            }
            return hasaudio;
        }

        public Boolean ExcuteNoresultsQuery(String sqlCommand)
        {
            DBConnection DB = new DBConnection();
            //DB.cnTransact.Open();
            if (DB.ExecuteCommandNonquery(sqlCommand))
            {
                return true;
            }
            else
            {
                return false;
            }
            //DB.cnTransact.Close();


        }
        public string getRoomName(string sqlcommand)
        {
            string item = "";
            DBConnection DB = new DBConnection();
            //DB.cnTransact.Open();
            SqlDataReader myReader = DB.ExecuteCommandquery(sqlcommand);
            while (myReader.Read())
            {
                item = myReader[0].ToString();
            }
            return item;
        }
       
    }
}